<?php
namespace app\api\v1\controller;

use think\Controller;
use think\Request;
use think\Config;
use lmxdawn\jwt\JWT;

class ApiBase extends Controller
{
	public function __construct(Request $request)
    {
        parent::__construct($request);
        Config::load(APP_PATH . 'api/v1/config.php');
        $key = config('key');
        $jwt = $request->param('jwt');
        try{
            \lmxdawn\jwt\JWT::$leeway = 60;//时间差
            $decoded = JWT::decode($jwt, $key, array('HS256'));
            //获取jwt里的用户信息
            $username = $decoded->sub->username;
            //根据用户信息去找用户
            dump($username);
        }catch (Exception $e){
            header('Content-type:application/json;charset=utf-8');
            echo json_encode(['status' => 1, 'msg' => $e->getMessage(), [], 400]);
        }

    }
}